
$(function() {

	var tabType = $("#tabType").val();
	if (tabType === "listTab") {
		$("#listTab").addClass("active");
		$("a.pageUrl").each(function() {
			$(this).attr("href", "listhome" + $(this).attr("href"));
		});
	} else if (tabType === "feedTab") {
		$("#feedTab").addClass("active");
		$("a.pageUrl").each(function() {
			$(this).attr("href", "feedhome" + $(this).attr("href"));
		});
	}

	$("body")
			.append(
					"<form action='search' id='tagForm' method='post'> <input id='tagfield' type='hidden' name='keyword'> </form>");
	$(".linkTag").click(function() {
		$('#tagfield').val($(this).text());
		$('form#tagForm').submit();
	});

	var currentPage = $("#currentPage").val();
	$("a.pageUrl").each(function() {
		if (currentPage == $(this).text())
			$(this).parent().addClass("active");
	});
	initFollowForm();

	$('.followBtn').click(function() {
		$(this).button("loading");
		var action = $(this).attr("action");
		var btn = this;
		$.post(action, {
			"fid" : $(this).attr("fid")
		}, function(data) {
			if (action === "follow") {
				$(btn).button("complete");
				$(btn).attr("action", "unfollow");
			} else {
				$(btn).button("reset");
				$(btn).attr("action", "follow");
			}
		});
	});
	$('#submitUrl').click(function() {
		$.get("getLinkForm", {
			"linkUrl" : $('#linkUrl').val()
		}, function(response) {
			$('#addLink').modal('hide');
			$('#saveLink').html(response);
			$('#saveLink').modal('show');
		});
	});
	$('button.editLink').click(function() {
		$.get("getEditLinkForm", {
			"bid" : $(this).val()
		}, function(response) {
			$('#saveLink').html(response);
			$('#saveLink').modal('show');
		});
	});
	
	
	/*$('#ckepop a').mouseenter(function() {
		var body = $(this).parents().filter("#listTab .row").find(".body");
		var url = body.find("a").attr("href");
		var title = body.find("a").attr("title");
		jiathis_config = {
			"url" : "url",
			"summary":"来自美味书签带着爱"
		};
	});*/
});

function initFollowForm() {
	$('.followBtn').each(function() {
		var action = $(this).attr("action");
		if (action === "follow") {
			$(this).button("reset");
		} else {
			$(this).button("complete");
		}
	});
}